package com.mmall.util;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Date;

/**
 * Created by root on 18-4-7.
 */
public class DateTimeUtil {

    public final static String STANDARD_FORMAT = "yyyy-mm-dd ";

    public static Date strToDate(String dateTimeStr, String formatStr){
        DateTimeFormatter formatter = DateTimeFormat.forPattern(formatStr);
        DateTime dateTime = formatter.parseDateTime(dateTimeStr);
        return dateTime.toDate();
    }

    public static String dateToStr(Date date, String formatStr){
        if (date == null) {
            return "";
        }
        DateTime dateTime = new DateTime(date);
        return dateTime.toString(formatStr);
    }

    public static  Date strToDate(String dateTimeStr){
        return strToDate(dateTimeStr, STANDARD_FORMAT);
    }

    public static String dateToStr(Date date){
       return dateToStr(date, STANDARD_FORMAT);
    }
}
